﻿CREATE PROCEDURE [util].[JobFailureNotification]
@Subject NVARCHAR (256), @Message NVARCHAR (4000)
AS
BEGIN
	SET NOCOUNT ON
	
	DECLARE @RC int
	SET @RC = 0

	DECLARE @ServerMailBox nvarchar(100), @DBAMailBox nvarchar(100)
	EXEC @RC = config.GetMailBoxes @ServerMailBox OUTPUT ,@DBAMailBox OUTPUT
	IF(@RC <> 0)
		GOTO ERROR_HANDLER

	EXEC @RC = util.SendCDOMail @From = @ServerMailBox
		,@To = @DBAMailBox
		,@Subject = @Subject
		,@Body = @Message

	GOTO EXIT_PROC

ERROR_HANDLER:
	RAISERROR('Failed to send job failure notification: %s',16,1,@Subject)

EXIT_PROC:
	RETURN(@RC)
END